package com.education.service.task;

import com.education.common.utils.SpringBeanManager;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 任务管理器
 * @author Jason
 * @version 1.0.0
 * @date 2021-11-20 23:58
 */
public class TaskManager {

    private ThreadPoolTaskExecutor threadPoolTaskExecutor;

    public TaskManager(ThreadPoolTaskExecutor threadPoolTaskExecutor) {
        this.threadPoolTaskExecutor = threadPoolTaskExecutor;
    }

    public void pushTask(TaskParam taskParam) {
        TaskListener taskListener = SpringBeanManager.getBean(taskParam.getTaskListenerClass());
        if (taskListener != null) {
            threadPoolTaskExecutor.execute(() -> {
                taskListener.onMessage(taskParam);
            });
        }

    }
}
